// Copyright 2009, Google Inc. All Rights Reserved.
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0 
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * This code sample retrieves the list of accounts for authenticated user.
 *
 * To generate an XML Web Service Proxy Class you need to:
 * 1. Run Web Services Description Language Tool wsdl.exe from "$Microsoft Visual Studio Install Directory$\SDK\v2.0\Bin".
 *    wsdl http://server[:port]/services/v1/adminservice?wsdl /language:CS /protocol:SOAP /namespace:SampleCode.com.google.DataAPI.AdminService /out:AdminService.cs
 * 2. Copy obtained AdminService.cs into the project folder and add it to the project.
 */

using SampleCode.com.google.DataAPI.AdminService;

using System;

namespace AdminServiceGetAccountListSOAP
{
	public class GetAccountList
	{
		// Provide login information.
		private const string login = "YOUR_LOGIN";
		private const string password = "YOUR_PASSWORD";

		static void Main()
		{
			try
			{
				// Set up service connection.
				adminservice adminService = new adminservice();
				// Get account list.
				Account[] accounts = adminService.getAccountList(login, password);
				// Display accounts info.
				foreach (Account account in accounts)
					DisplayAccount(account);
			}
			catch(Exception e)
			{
				Console.WriteLine(e);
			}
		}

		private static void DisplayAccount(Account account)
		{
			Console.Write("Account id is \"" + account.accountId + "\", ");
			Console.Write("name is \"" + account.accountName + "\", ");
			Console.Write("contact name is \"" + account.contactName + "\", ");
			Console.Write("e-mail is \"" + account.emailAddress + "\" ");
			Console.WriteLine("and phone number is \"" + account.phoneNumber + "\".");
		}
	}
}
